<style scoped lang='less'>
    .holiday-list-mian {
        .action-cell {
            margin-bottom: 20px;
        }

        .home-list .search-block {
            display: flex;
            margin-bottom: 10px;
        }

        .input-search {
            margin-right: 10px;
            margin-bottom: 10px;
        }

        .home-list .selected-search {
            height: 200px;
            width: 100%;
            position: relative;
            border-radius: 4px;
            margin-bottom: 10px;

        }

        .home-list .selected-search .search-action {
            position: absolute;
            top: 10px;
            left: 10px;
            right: 10px;
        }

        .home-list .selected-search .selected-arr {
            position: absolute;
            top: 50px;
            left: 20px;
            right: 20px;
            bottom: 10px;
            overflow: scroll;
        }

        .home-list .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 10px;
            font-weight: 500;
            text-align: center;
            width: 260px;
            margin-bottom: 10px;
        }

        .home-list .selected-search .selected-arr .selected-item {
            /*border-bottom: 1px solid #dfdfdf;*/
            margin-bottom: 10px;
            font-size: 15px;
        }
    }

</style>
<template>
    <div class="holiday-list-mian">
        <h4>销假列表</h4>
        <Alert show-icon>
            此处显示当前用户需要销假的列表。
        </Alert>
<!--        <ButtonGroup>-->
<!--            <Button type="success" @click="jumpPage('','HolidayApply')">-->
<!--                <Icon type="md-add-circle" />-->
<!--                添加-->
<!--            </Button>-->
<!--        </ButtonGroup>-->
        <Table :context="self" :data="tableData" :columns="tableColumns" stripe border></Table>
<!--        <div style="margin: 10px;overflow: hidden;">-->
<!--            <div style="float: right;">-->
<!--                <Page :total="total" size="large" show-total :current="current" show-elevator show-sizer-->
<!--                      @on-change="changePage"></Page>-->
<!--            </div>-->
<!--        </div>-->
        <!--审核操作-->
        <!--<Modal v-model="setCheckIsShow" title="假条审核" @on-ok="handleSubmit('formValidate')"-->
               <!--@on-cancel="setPwdIsShow =false">-->
            <!--<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">-->
                <!--<Form-item label="审核状态" prop="checkState">-->
                    <!--<i-select v-model="formValidate.checkState" placeholder="请选择审核状态">-->
                        <!--<i-option value="通过">通过</i-option>-->
                        <!--<i-option value="拒绝">拒绝</i-option>-->
                        <!--<i-option value="转交">转交</i-option>-->
                    <!--</i-select>-->
                <!--</Form-item>-->
                <!--<Form-item label="是否需要其他审核员审核" prop="isNeedOtherChecker">-->
                    <!--<i-select v-model="formValidate.isNeedOtherChecker" placeholder="请选择是否需要其它审核员审核">-->
                        <!--<i-option value="true">需要</i-option>-->
                        <!--<i-option value="false">不需要</i-option>-->
                    <!--</i-select>-->
                <!--</Form-item>-->
                <!--<template v-if="formValidate.isNeedOtherChecker == 'true'">-->
                    <!--<selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>-->
                <!--</template>-->
                <!--<Form-item label="原因" prop="reason">-->
                    <!--<Input v-model="formValidate.reason" placeholder="请输入原因"></Input>-->
                <!--</Form-item>-->
            <!--</Form>-->
        <!--</Modal>-->
    </div>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import {Modal} from 'view-design';
    import selectSearch from '../../components/selectSearch';


    export default {
        data() {
            return {
                //选择部门
                selectBaseInfo: {
                    "title": '选择组织结构',
                    "placeholder": '请输入所在组织名称',
                    "postUrl": apiUtil.urls.OrganSearch,
                },
                reqpeopleDept: '',
                //下级审核员
                modalIsShow: true,
                nextName: '',
                principalId: '',
                principalArr: [],
                personalName: '请搜索',
                selectPeopelIsShow: false,
                nextRow: '',
                //审核
                setCheckIsShow: false,
                formValidate: {
                    checkState: '',
                    reason: '',
                    isNeedOtherChecker: '',
                },
                ruleValidate: {},
                checkRow: '',
                //表格数据
                self: this,
                tableData: [],
                total: 0,
                current: 1,
                tableColumns: [
                    {
                        title: '请假人',
                        key: 'Displayname',
                        align: 'center',
                    },
                    {
                        title: '开始日期',
                        key: 'Startdate',
                        align: 'center',
                    },
                    {
                        title: '返回日期',
                        key: 'Enddate',
                        align: 'center',
                    },
                    {
                        title: '外出地址',
                        key: 'Destination',
                        align: 'center',
                    },
                    {
                        title: '请假原因',
                        key: 'Reason',
                        align: 'center',
                    },
                    {
                        title: '请假类型',
                        key: 'RestType',
                        align: 'center',
                    },
                    {
                        title: '审核状态',
                        key: 'State',
                        align: 'center',
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            if(params.row.State == '待销假' || params.row.State == '拒绝' || params.row.State == '取消'){
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small',
                                            disabled:false
                                        },
                                        style: {
                                            // background: '#e4e4e4',
                                            // border: '1px solid #d5d5d5',
                                            // 'margin-bottom':'10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.cancelApply(params.row)
                                            }
                                        }
                                    }, '销假'),
                                ])
                            }else{

                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small',
                                            disabled:true
                                        },
                                        style: {
                                            // background: '#e4e4e4',
                                            // border: '1px solid #d5d5d5',
                                            // 'margin-bottom':'10px',
                                        },
                                        on: {
                                            click: () => {
                                                this.cancelApply(params.row)
                                            }
                                        }
                                    }, '销假'),
                                ])
                            }
                        }
                    }
                ]
            }
        },
        mounted() {
            this.mockTableData();
        },
        components: {
            selectSearch
        },
        component: {
            Modal
        },
        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            mockTableData() {
                let that = this;

                let para = {
                    creatorId: sessionStorage.getItem('userId'),
                }
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.FinishRest, para, function (res) {
                    that.$Loading.finish();
                    // that.total = res.Msg.TotalCount;
                    // that.current = res.Msg.CurrentPage;
                    that.tableData = res.Msg;

                    console.log('tableData:', res)
                });

            },
            cancelApply:function(row){
                let that = this;

                let para = {
                    restId: row.Id,
                    opId:  sessionStorage.getItem('userId'),
                }
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.FinishRestRequest, params, function (res) {
                    that.$Loading.finish();
                    // that.total = res.Msg.TotalCount;
                    // that.current = res.Msg.CurrentPage;
                    that.$Notice.open({
                        title: '提示',
                        desc: '销假成功 '
                    });
                    that.mockTableData();

                    console.log('tableData:', res)
                });
            },
            changePage(row) {
                // 这里直接更改了模拟的数据，真实使用场景应该从服务端获取数据
                console.log("row", row);
                this.current = row;
                this.images = [];
                this.mockTableData();
            },
            /**
             * 选择
             */

            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
                this.mockTableData();
            },

        },
    }
</script>
